// pages/exam/exam.js
Page({

  /** 
   * 页面的初始数据
   */
  data: {
    exam_list: [],
    images: [],
    kind: "0",
    exam: {},
    classes: [],
    current: "",
    btn: false,
  },

  add: function() {
    wx.navigateTo({
      url: '../exam_new/exam_new?examId=',
    })
  },

  bindBanjiChange: function(e) {
    const val = e.detail.value
    this.setData({
      current: val[0] + 1
    })
  },

  confirm: function() {
    wx.navigateTo({
      url: '../exam_marking/exam_marking?current=' + this.data.current,
    })
  },
  generateImages: function(num = 12) {
    const image_list = ["/images/shuta.png", "/images/hema.png", "/images/huanxiong.png", "/images/haiyaoyu.png", "/images/houzi.png", "/images/baitu.png", "/images/yanjingshe.png", "/images/she.png", "/images/hudie.png", "/images/pangxie.png", "/images/daishu.png", "/images/luotuo.png", "/images/tuoniao.png", "/images/hashiqi.png"]

    var images_temp = []
    for (var i = 0; i < num; i++) {
      var picture = Math.floor(Math.random() * 14)
      images_temp.push(image_list[picture])
    }
    return images_temp

  },

  jumpToExam: function(e) {
    var that = this
    console.log(e.currentTarget)
    var status = e.currentTarget.dataset.status
    var examId = e.currentTarget.dataset.exam
    var selectType = e.currentTarget.dataset.selecttype
    var markType = e.currentTarget.dataset.marktype
    console.log(markType, selectType)

    // if (that.data.kind == "3") {
    wx.navigateTo({
      url: '../exam_new/exam_new?examId=' + examId,
    })
    // } else {
    //   if (status == "0") {
    //     wx.showModal({
    //       title: '哎呀～',
    //       content: '此实验还未开始验收',
    //       success: function (res) {
    //         if (res.confirm) {
    //           console.log('用户点击确定')
    //         } else if (res.cancel) {
    //           console.log('用户点击取消')
    //         }
    //       }
    //     })
    //   } else if (status == "1") {
    //     if (that.data.kind == "1") {
    //       wx.navigateTo({
    //         url: "../exam_signin/exam_signin?exam_id=" + examId
    //       })
    //     } else if (that.data.kind == "2" || that.data.kind == "3" || that.data.kind == "4") {
    //       wx.showModal({
    //         title: '提示～',
    //         content: '此实验正在签到中',
    //         success: function (res) {
    //           if (res.confirm) {
    //             console.log('用户点击确定')
    //           } else if (res.cancel) {
    //             console.log('用户点击取消')
    //           }
    //         }
    //       })
    //     }

    //   } else if (status == "2") {
    //     if (that.data.kind == "2") {
    //       wx.navigateTo({
    //         url: "../exam_marking/exam_marking?exam_id=" + examId + "&markType=" + markType + "&selectType=" + selectType
    //       })
    //     } else if (that.data.kind == "1") {
    //       wx.navigateTo({
    //         url: "../exam_marking/exam_marking?student=dui" + "&exam_id=" + examId
    //       })
    //     } else if (that.data.kind == "3" || that.data.kind == "4") {
    //       wx.showModal({
    //         title: '提示～',
    //         content: '此实验正在打分中',
    //         success: function (res) {
    //           if (res.confirm) {
    //             console.log('用户点击确定')
    //           } else if (res.cancel) {
    //             console.log('用户点击取消')
    //           }
    //         }
    //       })
    //     }

    //   } else if (status == "3") {
    //     wx.showModal({
    //       title: '哎呀～',
    //       content: '此实验已验收结束',
    //       success: function (res) {
    //         if (res.confirm) {
    //           console.log('用户点击确定')
    //         } else if (res.cancel) {
    //           console.log('用户点击取消')
    //         }
    //       }
    //     })
    //   }
    // }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this

    //获取所有实验列表
    wx.request({
      url: getApp().globalData.my_server + "/mark/get_all_the_exams",
      data: {},
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function(res) {
        console.log(res)
        if (res.data.error_no == 2) {
          wx.showModal({
            title: '哎呀～',
            content: res.data.error_msg,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else if (res.data.error_no == 0) {
          var images_temp = that.generateImages(res.data.exams.length)
          console.log(images_temp)
          that.setData({
            exam_list: res.data.exams,
            images: images_temp,
            kind: getApp().globalData.kind
          })
        }
      },
      fail: function(res) {
        wx.showModal({
          title: '哎呀～',
          content: '获取已有实验列表失败',
          success: function(res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
        console.log("fail!", res)
      },
      complete: function(res) {

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})